package ajax;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import entitybean.oc_property_tools.EntityBean_Oc_Property_Tools;
import entitybean.oc_property_tools_ben.EntityBean_Oc_Property_Tools_Ben;
import entitybean.oc_property_tools_ice.EntityBean_Oc_Property_Tools_Ice;
import entitybean.oc_property_tools_pla.EntityBean_Oc_Property_Tools_Pla;
import entitybean.oc_station.EntityBeanOc_Station;
import entitybean.oc_station_ben.EntityBeanOc_Station_Ben;
import entitybean.oc_station_ice.EntityBeanOc_Station_Ice;
import entitybean.oc_station_pla.EntityBeanOc_Station_Pla;
import entitybean.oc_user_name.EntityBeanOc_User_Name;
import entitybean.oc_voyage.EnitityBeanOc_Voyage;
import entitybean.oc_voyage_ben.EnitityBeanOc_Voyage_Ben;
import entitybean.oc_voyage_ice.EnitityBeanOc_Voyage_Ice;
import entitybean.oc_voyage_pla.EnitityBeanOc_Voyage_Pla;
import service.ajax.Service_Ajax;
import service.service_admin.Service_Admin;
import service.service_search.Service_Search;

public class Ajax_voyage extends DispatchAction {
	private static final long serialVersionUID = 3968003872381932815L;
	private Service_Ajax service_ajax;
	private Service_Search service_search;
	private Service_Admin service_admin;
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}

	public Service_Ajax getService_ajax() {
		return service_ajax;
	}

	public void setService_ajax(Service_Ajax serviceAjax) {
		service_ajax = serviceAjax;
	}

	public String Ajax_station_load(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);

		List<EntityBeanOc_Station> list = this.service_ajax
				.Find_Oc_Station_by_oc_voyage_id(j);
		System.out.println("list.size()" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getStation_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public String Ajax_station_load_pla(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBeanOc_Station_Pla> list = this.service_ajax
				.Find_Oc_Station_Pla_by_oc_voyage_id(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getStation_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public String Ajax_station_load_ice(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBeanOc_Station_Ice> list = this.service_ajax
				.Find_Oc_Station_Ice_by_oc_voyage_id(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getStation_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public String Ajax_station_load_ben(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBeanOc_Station_Ben> list = this.service_ajax
				.Find_Oc_Station_Ben_by_oc_voyage_id(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getStation_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public ActionForward Ajax_voyage_load_page(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("载入海域和航次的综合数据做查询");
		String id = request.getParameter("id");
		String s_sea_area = request.getParameter("s_sea_area");
		System.out.println("s_sea_area=" + s_sea_area);
		Integer j = Integer.valueOf(id);
		if (s_sea_area != null && !s_sea_area.equals("")) {
			Integer k = Integer.valueOf(s_sea_area);
			List<EntityBeanOc_Station> list = this.service_ajax
					.Find_Oc_Station_by_oc_voyage_id(j, k);
			request.setAttribute("list", list);
		} else {
			List<EntityBeanOc_Station> list = this.service_ajax
					.Find_Oc_Station_by_oc_voyage_id(j);
			request.setAttribute("list", list);
		}

		return mapping.findForward("success");
	}

	public  ActionForward Ajax_voyage_load_page_ice(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		System.out.println("载入海域和航次的综合数据做查询");
		String id=request.getParameter("id");
		String s_sea_area=request.getParameter("s_sea_area");
		System.out.println("s_sea_area="+s_sea_area);
		Integer j = Integer.valueOf(id);
		if(s_sea_area!=null&&!s_sea_area.equals(""))
		{
			Integer k =Integer.valueOf(s_sea_area);
			List<EntityBeanOc_Station_Ice> list = this.service_ajax
			.Find_Oc_Station_Ice_by_oc_voyage_id(j, k);
	request.setAttribute("list", list);
		}
		else
		{
			List<EntityBeanOc_Station_Ice> list = this.service_ajax.Find_Oc_Station_Ice_by_oc_voyage_id(j);
			request.setAttribute("list", list);
		}
		
		return mapping.findForward("success");
	}

	public  ActionForward Ajax_voyage_load_page_ben(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		System.out.println("载入海域和航次的综合数据做查询");
		String id=request.getParameter("id");
		String s_sea_area=request.getParameter("s_sea_area");
		System.out.println("s_sea_area="+s_sea_area);
		Integer j = Integer.valueOf(id);
		if(s_sea_area!=null&&!s_sea_area.equals(""))
		{
			Integer k =Integer.valueOf(s_sea_area);
			List<EntityBeanOc_Station_Ben> list = this.service_ajax
			.Find_Oc_Station_Ben_by_oc_voyage_id(j, k);
			request.setAttribute("list", list);
		}
		else
		{
			List<EntityBeanOc_Station_Ben> list = this.service_ajax.Find_Oc_Station_Ben_by_oc_voyage_id(j);
			request.setAttribute("list", list);
			
		}
		
		
		return mapping.findForward("success");
	}

	public  ActionForward Ajax_voyage_load_page_pla(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		System.out.println("载入海域和航次的综合数据做查询");
		String id=request.getParameter("id");
		String s_sea_area=request.getParameter("s_sea_area");
		System.out.println("s_sea_area="+s_sea_area);
		Integer j = Integer.valueOf(id);
		if(s_sea_area!=null&&!s_sea_area.equals(""))
		{
			Integer k =Integer.valueOf(s_sea_area);
			List<EntityBeanOc_Station_Pla> list = this.service_ajax
			.Find_Oc_Station_Pla_by_oc_voyage_id(j, k);
	request.setAttribute("list", list);
	request.setAttribute("list", list);
		}
		else
		{
			List<EntityBeanOc_Station_Pla> list = this.service_ajax.Find_Oc_Station_Pla_by_oc_voyage_id(j);
			request.setAttribute("list", list);
		}
		
		
		return mapping.findForward("success");
	}

	public String Ajax_tools_load_ben(String id) {

		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBean_Oc_Property_Tools_Ben> list = this.service_ajax
				.Find_Oc_Property_Tools_Ben_by_id(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getTools_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);

		return strword;

	}

	public String Ajax_tools_load_ice(String id) {

		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBean_Oc_Property_Tools_Ice> list = this.service_ajax
				.Find_Oc_Property_Tools_Ice_by_id(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getTools_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);

		return strword;

	}

	public String Ajax_tools_load(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBean_Oc_Property_Tools> list = this.service_ajax
				.Find_Oc_Property_Tools_by_id(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getTools_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);

		return strword;
	}

	public String Ajax_voyage_load(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EnitityBeanOc_Voyage> list = this.service_ajax
				.Find_Oc_Voyage_By_boatid(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getVoyage_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public String Ajax_voyage_load_ice(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EnitityBeanOc_Voyage_Ice> list = this.service_search
				.Find_Oc_Voyage_Ice_By_boatid(j);
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getVoyage_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public String Ajax_voyage_load_pla(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EnitityBeanOc_Voyage_Pla> list = this.service_search
				.Find_Oc_Voyage_Pla_By_boatid(j);
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getVoyage_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}

	public String Ajax_tools_load_pla(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EntityBean_Oc_Property_Tools_Pla> list = this.service_search
				.Find_EntityBean_Oc_Property_Tools_Pla_by_property_id(j);
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getTools_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);

		return strword;
	}

	public String Ajax_voyage_load_ben(String id) {
		String strword = "";
		Integer j = Integer.valueOf(id);
		List<EnitityBeanOc_Voyage_Ben> list = this.service_ajax
				.Find_Oc_Voyage_Ben_By_boatid(j);
		System.out.println("list.size()=" + list.size());
		for (int i = 0; i < list.size(); i++) {
			strword = strword + list.get(i).getId() + ",";
			strword = strword + list.get(i).getVoyage_name() + ",";
		}
		System.out.println("strword=" + strword + " id=" + id);
		return strword;
	}
	public String Ajax_voyage_load_username(String id) {
		String[] a=id.split(",");
		String username=a[0];
		String email=a[1];
		List<EntityBeanOc_User_Name>  list= this.service_admin.Find_EntityBeanOcByName(username);
		List<EntityBeanOc_User_Name>  list2= this.service_admin.Find_EntityBeanOcByMail(email);
        if(list.size()>0){
       	    return "1";
        }else if(list2.size()>0){
       	    return "2";
        }else{
        	return "3";
        }
	}
	public String Ajax_voyage_load_username_id(String id) {
		String[] a=id.split(",");
		String ids=a[0];
		String username=a[1];
		String email=a[2];
		List<EntityBeanOc_User_Name>  list= this.service_admin.Find_EntityBeanOcByName(username,ids);
		List<EntityBeanOc_User_Name>  list2= this.service_admin.Find_EntityBeanOcByMail(email,ids);
        if(list.size()>0){
       	    return "1";
        }else if(list2.size()>0){
       	    return "2";
        }else{
        	return "3";
        }
	}
}
